package cn.iocoder.yudao.module.form.controller;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.form.dataobject.FormChart;
import cn.iocoder.yudao.module.form.dataobject.FormTable;
import cn.iocoder.yudao.module.form.dataobject.FormTableColumn;
import cn.iocoder.yudao.module.form.service.IDatabaseDomainService;
import cn.iocoder.yudao.module.form.service.IFormService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

//import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * <p>
 * 土地污染 自研报表模块
 * </p>
 *
 * @author Fan KaiXiang
 * @since 2022-08-01
 */

@Api(tags = "a自研报表")
@RestController
@RequestMapping("/admin-api")
@Validated
public class FormController  {
    @Autowired
    private IFormService formService;

    @Autowired
    private IDatabaseDomainService databaseDomainService;

    @GetMapping("getTablesInDataBase")
    @ApiOperation(value = "获取数据库内所有的表", notes = "获取数据库内所有的表")
    public CommonResult<List<FormTable>> getTablesInDataBase() {
        List<FormTable> fb = formService.getTable();
        return success(fb);
    }

    @GetMapping("getTablesColumn")
    @ApiOperation(value = "获取表的列名", notes = "获取表的列名")
    public CommonResult<List<FormTableColumn>> getTablesColumn(String tableName) {
        List<FormTableColumn> fbc = formService.getTableColumn(tableName);
        return success(fbc);
    }

    /**
     * 初始化报表内图表
     */
    @GetMapping(value = "initForm")
    @ApiOperation(value = "初始化报表内图表", notes = "初始化报表内图表")
    public CommonResult<ArrayList<FormChart>> initForm(Long formId) {
        return success(formService.initForm(formId));
    }

    /**
     * 在报表中新建图表
     */
    @PostMapping(value = "insertIntoFormChart")
    @ApiOperation(value = "在报表中新建图表", notes = "在报表中新建图表")
    public CommonResult<Long> insertIntoFormChart(@RequestBody FormChart formChart) {
        return success(formService.insertIntoFormChart(formChart));
    }

    /**
     * 在报表中修改图表
     */
    @PostMapping(value = "updateFormChart")
    @ApiOperation(value = "在报表中修改图表", notes = "在报表中修改图表")
    public CommonResult<FormChart> updateIntoFormChart(@RequestBody FormChart formChart) {
        return success(formService.updateFormChart(formChart));
    }

    /**
     * 在报表中删除图表
     */
    @GetMapping(value = "deleteFormChart")
    @ApiOperation(value = "在报表中删除图表", notes = "在报表中删除图表")
    public CommonResult<Long> deleteFormChart(Long chartId, Long formId) {
        return success(formService.deleteFormChart(chartId, formId));
    }

    @GetMapping("getlineChart")
    @ApiOperation(value = "获取折线图", notes = "获取折线图")
    public CommonResult<HashMap<String, Object>> getlineChart(String tableName, String xcolumn, String ycolumn) {

        return success(formService.getlineChart(tableName, xcolumn, ycolumn));
    }

    @GetMapping("getSimpleBarChart")
    @ApiOperation(value = "获取基础柱状图", notes = "获取基础柱状图")
    public CommonResult<HashMap<String, Object>> getSimpleBarChart(String tableName, String xcolumn, String ycolumn) {
        return success(formService.getSimplebarChart(tableName, xcolumn, ycolumn));
    }

    @GetMapping("getStackedColumnChart")
    @ApiOperation(value = "获取堆叠柱状图", notes = "获取堆叠柱状图")
    public CommonResult<HashMap<String, Object>> getStackedColumnChart(String tableName, String xcolumn, String ycolumn, String type) {
        return success(formService.getStackedColumnChart(tableName, xcolumn, ycolumn, type));
    }

    @GetMapping("getMulDataChart")
    @ApiOperation(value = "获取多数据柱状图", notes = "获取多数据柱状图")
    public CommonResult<HashMap<String, Object>> getMulDataChart(String tableName, String xcolumn, String ycolumn, String type) {
        return success(formService.getMulDataChart(tableName, xcolumn, ycolumn, type));
    }

    @GetMapping("getLineColumnChart")
    @ApiOperation(value = "获取折线柱状图", notes = "获取折线柱状图")
    public CommonResult<HashMap<String, Object>> getLineColumnChart(String tableName, String xcolumn, String ycolumn1, String ycolumn2) {
        return success(formService.getLineColumnChart(tableName, xcolumn, ycolumn1, ycolumn2));
    }

    @GetMapping("getParetoChart")
    @ApiOperation(value = "获取帕累托图", notes = "获取帕累托图")
    public CommonResult<HashMap<String, Object>> getParetoChart(String tableName, String xcolumn, String ycolumn) {
        return success(formService.getParetoChart(tableName, xcolumn, ycolumn));
    }

    @GetMapping("getSumSortChart")
    @ApiOperation(value = "获取合并累加排序柱状图", notes = "获取合并累加排序柱状图")
    public CommonResult<HashMap<String, Object>> getSumSortChart(String tableName, String xcolumn, String ycolumn) {
        return success(formService.getSumSortChart(tableName, xcolumn, ycolumn));
    }

    @GetMapping("getPieChart")
    @ApiOperation(value = "获取饼状图(基础饼状图、环形图、南丁格尔玫瑰图)", notes = "获取饼状图(基础饼状图、环形图、南丁格尔玫瑰图)")
    public CommonResult<HashMap<String, Object>> getPieChart(String tableName, String xcolumn, String ycolumn) {
        return success(formService.getPieChart(tableName, xcolumn, ycolumn));
    }

    @GetMapping("getRadarChart")
    @ApiOperation(value = "获取雷达图", notes = "获取雷达图")
    public CommonResult<HashMap<String, Object>> getRadarChart(String tableName, String xcolumn, String ycolumn1,String ycolumn2,
                                                               String ycolumn3,String ycolumn4,
                                                               String ycolumn5,String ycolumn6) {
        return success(formService.getRadarChart(tableName, xcolumn, ycolumn1,ycolumn2,ycolumn3,ycolumn4,ycolumn5,ycolumn6));
    }

}
